<?php 


/**
* 
*/
class RentingConceptoController extends Zend_Controller_Action
{
	
	function init()
	{
		$this->model = new Application_Model_RentingConcepto();
		$this->form = new Application_Form_Datacenter();
		$this->request=$this->getRequest();
	}

    

	
	public function indexAction()
	{
		
        $this->_helper->breadcrumbs->addStep('Renting',$this->view->baseUrl('renting'));
        $this->_helper->breadcrumbs->addStep('Seguimiento Renting','');
        
        $this->view->headTitle('Seguimiento Renting');

        $id_renting=$this->request->getParam('renting');

		$rows = $this->model->getAllByWhere(array('id_renting = ? '=>$id_renting));
        foreach($rows as $k => $v)
        {
            for($i=0;$i<$v['meses'];$i++){
                $fechas[$k][]=date('Y-m',strtotime($v['fecha_inicio']." +$i month"));
                $rows[$k]['fechas']=$fechas[$k];
            }
        }
        
        $f=array();
        foreach($fechas as $k => $v){
            $f=array_merge($f,$v);
        }
        $f=array_unique($f);

        $this->view->f=$f;

		$this->view->rows =$this->_helper->prepareRows($rows);

	}
	
	public function insertarAction()
    {
    	$this->_helper->insertar( $this->form, $this->_helper);
	}
	
	public function editarAction()
    {
    	$this->_helper->editar( $this->form, $this->_helper);
	}
	
	public function borrarAction()
	{
	   	$this->_helper->viewRenderer->setNoRender(TRUE);
    	$this->_helper->layout->disableLayout();
        
		$id=$this->request->getParam('id');
		$this->model->deleteById($id);
        
       	echo $this->view->json(array('status'=>'ok'));
        

	}
	
	
	function prepareValuesToTr($row)
	{

		return $row;
	}
	
	
	
	function prepareValuesToDb1()
	{
		$data=$this->form->getValues();
		
		
		if($this->view->actionName=='insertar'){
			$id=$this->model->insert($data);
		}else{
			$id=$this->request->getParam('id');
			$this->model->updateById($data,$id);
		}
		
		$row=$this->model->getRowById($id);
		return $this->prepareValuesToTr($row);
	}
	
}


